import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xvideos/hj_utils/widget_utils.dart';
import 'package:xvideos/tools_base/widget/keep_alive_widget.dart';

import '../../../assets_tool/app_colors.dart';
import '../../../tools_base/indicator/custom_tab_indicator.dart';
import 'pics_main_logic.dart';
import 'pics_sub_page.dart';

//套图站首页
class PicsMainpage extends StatefulWidget {
  const PicsMainpage({super.key});

  @override
  State<PicsMainpage> createState() => _PicsMainpageState();
}

class _PicsMainpageState extends State<PicsMainpage> {
  PicsMainLogic logic = Get.put(PicsMainLogic());

  @override
  Widget build(BuildContext context) {
    return GetBuilder<PicsMainLogic>(
      builder: (_) {
        return Column(
          children: [
            _buildTabbar(_),
            10.sizeBoxH,
            Expanded(
              child: TabBarView(
                controller: _.tabCtr,
                children: List.generate(
                  _.pics.length,
                  (index) => PicsSubPage(tagData: _.pics[index]).keepAlive,
                ),
              ),
            )
          ],
        );
      },
    );
  }

  _buildTabbar(PicsMainLogic _) {
    return SizedBox(
      height: 34,
      child: TabBar(
        controller: _.tabCtr,
        padding: EdgeInsets.only(left: 8),
        tabs: List.generate(
          _.pics.length,
          (index) => Padding(
            padding: const EdgeInsets.only(top: 6, bottom: 3),
            child: Text(_.pics[index].moduleName ?? ''),
          ),
        ),
        labelPadding: EdgeInsets.symmetric(horizontal: 8),
        tabAlignment: TabAlignment.start,
        isScrollable: true,
        labelColor: Colors.white,
        labelStyle: TextStyle(fontSize: 14, fontWeight: FontWeight.w600),
        unselectedLabelColor: AppColors.tipTextColor99,
        unselectedLabelStyle: TextStyle(fontSize: 14, fontWeight: FontWeight.w400),
        indicator: CustomIndicator(
          width: 22,
          height: 3,
          color: AppColors.primaryHighColor,
          topLeft: 2,
          topRight: 2,
          bottomLeft: 2,
          bottomRight: 2,
        ),
      ),
    );
  }
}
